package com.example.basicknowledge.RecyclerActivity;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.basicknowledge.R;

public class ReAdapter extends RecyclerView.Adapter<ReAdapter.ViewHolder> implements View.OnClickListener {
    private String[] mDatabase;



    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView mTextView;
        public ViewHolder (View itemView) {
            super(itemView);
            mTextView = itemView.findViewById(R.id.textView22);
        }
    }

    public ReAdapter(String[] database) {
        super();
        mDatabase = database;
    }

    @Override
    public int getItemCount() {
        return mDatabase.length;
    }

    @NonNull
    @Override
    public ReAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.adapter_view_holder,viewGroup,false);
        ViewHolder viewHolder = new ViewHolder(view);
        view.setOnClickListener(this);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
//        viewHolder.itemView.setTag(i);
        viewHolder.mTextView.setText(mDatabase[i]);
    }
    interface OnClickListener {
//        int itemPosition = RecyclerView.getChildLayoutPosition(view);
        void onClick(View view,int position);
    }

    private OnClickListener mOnClickListener = null;

    public void setTestOnClickListener(OnClickListener listener){
        mOnClickListener = listener;
    }

    @Override
    public void onClick(View view) {
        if (null != mOnClickListener){
//            mOnClickListener.onClick(view,(int)view.getTag());
        }
    }
}
